import React, { Component } from 'react';
import './addinput.css'
import { connect } from 'react-redux'
import { actionCreator,mapStateToProps,mapDispatchToProps } from '../../store/actions'
class AddInput extends Component {

  addItem = (ev) => {
    if (ev.keyCode === 13) {
      let val = {
        id:new Date().getTime(),
        todo: ev.target.value,
        done:false
      }
      this.props.add(actionCreator('add',val))
      ev.target.value=''
    }
  }
  render() {
    return (
      <div className='addinput'>
        <h2>TodoList</h2>
        <input type="text" placeholder='输入任务项目' onKeyUp={ this.addItem } />
      </div>
    );
  }
}

export default connect(mapStateToProps,mapDispatchToProps)(AddInput);